478B - Random Teams - CodeForces Solution


combinatorics constructive algorithms greedy math *1300

Please click on ads to support us..

Python Code:

n, m = map(int, input().split())
k1 = ((n//m)*(n//m -1)//2)*(m - (n%m)) + ((n//m + 1)*(n//m)//2)*(n%m)
k2 = (n-m+1)*(n-m)//2
print(k1,k2)

C++ Code:

#include<bits/stdc++.h>
using namespace std ;
#define ll long long int


ll pairs(ll n ) {
    return n * (n - 1) / 2 ;
}
int main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
#endif

    ll n, m ;
    cin >> n >> m ;
    ll a(n / m), b(n % m) ;
    ll min = pairs(a) * (m - b) + pairs(a + 1) * b ;
    ll max = pairs(n - m + 1) ;
    cout << min << " " << max << endl;
}


Comments

Submit
1 Comments
  • 8/5/2024 21:3 - Asia/Calcutta

where is the explaination, only code doesnt work, give me the explaination

 


More Questions

431B - Shower Line
282C - XOR and OR
1582B - Luntik and Subsequences
609A - Флеш-карты
1207A - There Are Two Types Of Burgers
371C - Hamburgers
343B - Alternating Current
758B - Blown Garland
1681B - Card Trick
1592A - Gamer Hemose
493D - Vasya and Chess
1485A - Add and Divide
337B - Routine Problem
1392D - Omkar and Bed Wars
76E - Points
762C - Two strings
802M - April Fools' Problem (easy)
577B - Modulo Sum
1555B - Two Tables
1686A - Everything Everywhere All But One
1469B - Red and Blue
1257B - Magic Stick
18C - Stripe
1203B - Equal Rectangles
1536A - Omkar and Bad Story
1509A - Average Height
1506C - Double-ended Strings
340A - The Wall
377A - Maze
500A - New Year Transportation